unit uLimpaProd;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,db,dbtables, StdCtrls, Buttons, Gauges;

type
  TfrmLimpaProd = class(TForm)
    pb: TGauge;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Label1: TLabel;
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmLimpaProd: TfrmLimpaProd;

implementation

uses Dm, clsProduto;

var
 Produto: TProduto;

{$R *.dfm}

procedure TfrmLimpaProd.BitBtn2Click(Sender: TObject);
begin
 Close;
end;

procedure TfrmLimpaProd.BitBtn1Click(Sender: TObject);
var
 tq: TQuery;
begin
 Produto:= TProduto.Create;

 tq:=TQuery.Create(DmInt);
 tq.DatabaseName:= DmInt.Db.DatabaseName;
 tq.Close;
 tq.Params.Clear;
 tq.SQL.Clear;
 tq.SQL.Add('Select Pro_Codigo from Produto');
 tq.Open;
 pb.MaxValue:= tq.RecordCount;
 while not tq.eof do begin
  pb.Progress:= pb.Progress + 1;
  if Produto.Excluir(tq.FieldByName('Pro_Codigo').AsString) = 1 then begin
   Label1.Caption:= 'Excluindo produto'+#13+tq.FieldByName('Pro_Codigo').AsString;
   Label1.Refresh;
  end;
  tq.Next;
 end;
 tq.Close;
 tq.Free;
 Produto.Free;
end;

procedure TfrmLimpaProd.FormActivate(Sender: TObject);
begin
 pb.MaxValue:= 0;
 pb.MinValue:= 0;
 pb.Progress:= 0;
end;

end.
